﻿using System;
using System.Collections.Generic;
using EmbeddedLanguage.Attributes;

namespace EmbeddedLanguage
{
    [JSNamespaceSubstition(Namespace = ObjectEx.RootNS)]
    public class Range<T> //: ICanNew<Range<T>>
    {

        #region ICanNew
        public RangeActionList OnNew
        {
            set
            {
                for (_Val = Start; _Val <= End; _Val++)
                {
                    foreach (Action<Range<T>> action in value)
                    {
                        action(this);
                        if (this._Break)
                        {
                            this._Break = false;
                            return;
                        }
                        if (this.Continue)
                        {
                            this.Continue = false;
                            break;
                        }
                    }
                }

            }
        }
        //public Range Do(List<Action<Range>> actions) { actions.ForEach(action => action(this)); return this; }
        #endregion

        public class RangeActionList : List<Action<Range<T>>> { }

        public int Start;
        public int End;
        private bool _Break;
        [KeywordSubstitution(
            JSKeyword = "break;"
        )]
        public Range<T> Break()
        {
            this._Break = true;
            return this;
        }
        public bool Continue;
        private int _Val;
        public int Val
        {
            get
            {
                return _Val;
            }
        }

        public T ReturnObj;
        


    }
}
